home *** CD-ROM | disk | FTP | other *** search
/ Pascal Super Library / Pascal Super Library (CW International)(1997).bin / TSR / PPTSR10 / FILER.PAS < prev    next >
Pascal/Delphi Source File  |  1993-02-12  |  4KB  |  181 lines

  1. (*
  2. Program  : filer.pas
  3. Function : Example TSR program to view a file. Very basic viewing !!
  4. Author   : P.Peters
  5. Date     : June 1992
  6. *)
  7. {$m $1000,0,0}
  8. {$r-,s-,x+}
  9. program filer;
  10. uses
  11.  crt,tsrutil,tsr;
  12. const
  13.  idcode   = $c3;
  14.  filename : string = '';
  15.  
  16. var
  17.  fil      : text;
  18.  scr      : array[1..4000] of byte;
  19.  sat      : byte;
  20.  
  21. function fileexists( filename : string ) : boolean;
  22. var
  23.   f: file;
  24. begin
  25.   {$i-} assign( f,filename ); reset( f ); close( f ); {$i+}
  26.   fileexists := (ioresult = 0) and (filename <> '');
  27. end;
  28.  
  29. function waitkey : word;
  30. begin
  31.   write('Press any key to continue...');
  32.   repeat until keyavail;
  33.   waitkey := readkeycode;
  34.   write(^m);
  35.   clreol;
  36. end;
  37.  
  38. procedure filit; far;
  39. var s : string;
  40.     i : word;
  41.     k : word;
  42. begin
  43.   assign(fil,filename);
  44.   {$i-}reset(fil);{$i+}
  45.   if ioresult = 0 then begin
  46.     i := 0;
  47.     cursoroff;
  48.     savescreen(1,1,80,25,scr);
  49.     sat := textattr;
  50.     textbackground(white);
  51.     textcolor(black);
  52.     clrscr;
  53.     k := 0;
  54.     while (lo(k) <> 27) and (not eof(fil)) do begin
  55.       readln(fil,s);
  56.       writeln(s);
  57.       inc(i);
  58.       if (i mod 24) = 0 then k := waitkey;
  59.     end;
  60.     if (i mod 24) <> 0 then waitkey;
  61.     textattr := sat;
  62.     restorescreen(1,1,80,25,scr);
  63.     cursoron;
  64.   end;
  65.   {$i-}close(fil);{$i+}
  66. end;
  67.  
  68. procedure receiver; far; assembler;
  69. label
  70.   tst3,fin;
  71. asm
  72.   cmp   ax,2                {set file name}
  73.   jne   tst3
  74.   mov   ds,bx
  75.   mov   si,cx
  76.   mov   ch,0
  77.   mov   cl,ds:[si]
  78.   inc   cx
  79.   mov   bx,seg filename
  80.   mov   es,bx
  81.   mov   di,offset filename
  82.   repnz movsb
  83.   jmp   fin
  84. tst3:
  85.   cmp   ax,3  {get name}
  86.   jne   fin
  87.   mov   bx,seg filename
  88.   mov   cx,offset filename
  89. fin:
  90. end;
  91.  
  92. procedure paramcheck; far;
  93. var
  94.   s : string;
  95.   i : byte;
  96.  
  97.   procedure setfilename;
  98.   begin
  99.     filename := s;
  100.     if tsrloaded then begin
  101.       asm
  102.         pusha
  103.         mov  bx,seg filename
  104.         mov  cx,offset filename
  105.         mov  ax,idcode shl 8 + 2
  106.         int  2fh
  107.         popa
  108.       end;
  109.     end;
  110.   end;
  111.  
  112.   procedure getinfo;
  113.   begin
  114.     if tsrloaded then begin
  115.       asm
  116.         pusha
  117.         mov   ax,idcode shl 8 + 3
  118.         int   2fh
  119.         mov   ds,bx
  120.         mov   si,cx
  121.         mov   ch,0
  122.         mov   cl,ds:[si]
  123.         inc   cx
  124.         mov   bx,seg filename
  125.         mov   es,bx
  126.         mov   di,offset filename
  127.         repnz movsb
  128.         popa
  129.       end;
  130.       writeln('Info from Tsr');
  131.       writeln('  Filename : ',filename);
  132.     end else begin
  133.       writeln('Tsr receiver not installed.');
  134.       halt;
  135.     end;
  136.   end;
  137.  
  138.   procedure writeopt;
  139.   begin
  140.     writeln('Usage:');
  141.     writeln('  Filer [Option]');
  142.     writeln('Options:');
  143.     writeln('  /u     : Remove Tsr');
  144.     writeln('  /i     : Display this info from Tsr');
  145.     writeln('  <name> : file to display');
  146.     halt;
  147.   end;
  148.  
  149. begin
  150.   if paramcount > 0 then
  151.     for i := 1 to paramcount do begin
  152.       s := paramstr(i);
  153.       if s[1] = '/' then begin (* switch *)
  154.         delete(s,1,1);
  155.         s[1] := upcase(s[1]);
  156.         case s[1] of
  157.           'I' : getinfo;
  158.           '?' : writeopt;
  159.           else begin
  160.             writeln('Invalid switch : ',s);
  161.             writeopt;
  162.           end;
  163.         end;
  164.       end else begin (* no switch *)
  165.         if fileexists( s ) then
  166.           setfilename
  167.         else begin
  168.           Writeln(^g'File not found : ',s );
  169.           halt;
  170.         end;
  171.       end;
  172.     end;
  173. end;
  174.  
  175. begin
  176.   if paramcount = 0 then
  177.     writeln(^g'Parameter or switch required.')
  178.   else
  179.     tsrinstall('Alt-F',$2100,idcode,filit,receiver,paramcheck);
  180. end.
  181.